<?php
class Miscmodel extends BaseModel implements Model {
    function __construct() {
        parent::__construct("last_newsletter_date", "");
        $this->addField("last_newsletter_date", Model::TYPE_DATE);
    }

    public function getLastNewsletterDate() {
        $query = "SELECT last_newsletter_date FROM misc";
        $res = Database::executeQuery($query);
        $data = Database::getDatafromResource($res);
        return $data[0]['last_newsletter_date'];
    }

    public function getInvoiceNumber() {
        $query = "SELECT invoice_counter FROM misc";
        $res = Database::executeQuery($query);
        $number = intval(Database::getSimpleField($res), 10);
        $newNumber = $number + 1;
        $query = "UPDATE misc SET invoice_counter=$newNumber";
        Database::executeQuery($query);
        return $number;
    }

    public function renderAlias($record) {
        $result = $record;
        return $result;
    }

    public function isAuthorized($operation, $subject = "") {
        return true;
//        if (Auth::isAdmin()) { return true; }
/*
        switch ($operation) {
            case "update" :
            case "delete" :
            case "addnew" : {
                if (Auth::canChangeDrivers()) { return true; }
            }
            case "list" : {
                if (Auth::canListDrivers()) { return true; }
            }
        }
        return false;
*/
    }

    public function modifyDatabaseInput($data) {
        $result = array();
        return $result;
    }
}

?>
